package kgc.crm.controller;

import kgc.crm.annotation.UserPower;
import kgc.crm.annotation.VerificationToken;
import kgc.crm.enums.PowerEnum;
import kgc.crm.model.AdminDept;
import kgc.crm.model.User;
import kgc.crm.service.AdminDeptService;
import kgc.crm.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("dept")
@CrossOrigin
public class DeptController {
    @Autowired
    private AdminDeptService deptService;

    //查询级联部门
    @UserPower(power = PowerEnum.INDEX)
    @VerificationToken
    @GetMapping("list")
    public ResponseEntity list() {
        return ResultUtil.success(deptService.listAll());
    }

    //添加部门
    @UserPower(power = PowerEnum.DEPTSAVE)
    @VerificationToken
    @PostMapping("add")
    public ResponseEntity addDept(@RequestBody AdminDept dept) {
        return deptService.addDept(dept);
    }
    //编辑部门
    //部门名称 上级部门 部门负责人 都当做参数传进来
    @UserPower(power = PowerEnum.DEPTUPDATE)
    @VerificationToken
    @PostMapping("upd")
    public ResponseEntity updDept(@RequestBody AdminDept dept) {
     //   System.out.println(dept);
        return deptService.updDept(dept);
    }
    //删除部门
    @UserPower(power = PowerEnum.DEPTDELETE)
    @VerificationToken
    @PostMapping("del/Dept")
    public ResponseEntity delDept(@RequestBody AdminDept dept) {
        //   System.out.println(dept);
        return deptService.delDept(dept);
    }
}
